<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/1/8 0008
 * Time: 13:44
 */

namespace application\admin\controller;

use think\Db;
use think\Session;

class AppController extends CommonController
{
    public function index(){
        //echo '2';
        Session::get('user_id') != 1 ? $where['user_id'] = Session::get('user_id') : '';

        $data = Db::name('wechatapp')->where($where)->select();
      //  print_r($data);
        $this->assign('lists',$data);
        return $this->fetch();
    }
    /**
     * 编辑app配置
     */
    public function  info(){
        if(request()->isPost()){
            $id = $this->request->param('id');
            $map['company_name'] = $this->request->param('company_name');
            $map['appid'] = $this->request->param('appid');
            $map['appsecret'] = $this->request->param('appsecret');
            $map['token'] = $this->request->param('token');
            $map['appname'] = $this->request->param('appname');
            $map['app_type'] = $this->request->param('app_type');
            $result = Db::name('wechatapp')->where('app_id',$id)->update($map);
            if ($result){
                $this->success('操作成功', url('index'));
            }
        }
        $id = $this->request->param('id');
        $data = Db::name('wechatapp')->where('app_id',$id)->find();
        $this->assign('info',$data);
        return $this->fetch();
    }
    //添加
    public function add(){
        $map['company_name'] = $this->request->param('company_name');
        $map['appid'] = $this->request->param('appid');
        $map['appsecret'] = $this->request->param('appsecret');
        $map['appname'] = $this->request->param('appname');
        $map['token'] = $this->request->param('token');
        $map['app_type'] = $this->request->param('app_type');
        $map['addtime'] = date('Y-m-d H:i:s',time());
        $map['user_id'] = Session::get('user_id');
        $result = Db::name('wechatapp')->insert($map);
        if ($result){
            $this->success('操作成功', url('index'));
        }
    }
    public function del(){
        $id = $this->request->param('id');
        $result = Db::name('wechatapp')->where('app_id',$id)->delete();
        if ($result){
            $this->success('操作成功', url('index'));
        }
    }
}